package com.thinkwide.data.ormapping.dialect;

import com.thinkwide.data.core.MFString;

public class MFDb2Sql extends MFAbstractCrossSql {
    @Override
    public String getSelectPageSql(String tableName, String where, String orderBy, int beginIndex, int endIndex) {
        String sql = "SELECT * FROM (SELECT A.*,ROWNUM RN FROM (SELECT * FROM %s %s %s ) A) Where RN>%s AND RN<=%s ";

        String str = String.format(sql, tableName, where, orderBy, beginIndex, endIndex);
        return str;
    }

    @Override
    public String getSelectPageSqlExt(String sql, String where, String orderBy, int beginIndex, int endIndex) {
        String xwhere = "";
        if (MFString.notNullOrEmpty(where)) {
            xwhere = " where " + where;
        }

        String xorderBy = "";
        if (MFString.notNullOrEmpty(orderBy)) {
            xorderBy = " order by " + orderBy;
        }

        String sqlformat = "SELECT * FROM (SELECT A.*,ROWNUM RN FROM (%s ) A %s %s) Where RN>%s AND RN<=%s ";

        String str = String.format(sqlformat, sql, where, xorderBy, beginIndex, endIndex);
        return str;
    }

    @Override
    public String getSelectPageSql(String sql, int beginIndex, int endIndex) {
        String sqlformat = "SELECT * FROM (SELECT A.*,ROWNUM RN FROM (%s ) A) Where RN>%s AND RN<=%s ";

        String str = String.format(sqlformat, sql, beginIndex, endIndex);
        return str;
    }

    @Override
    public String translateSql(String sql, MFDBType oldType, MFDBType newType) {
        return null;
    }

    @Override
    public String translateSql(String sql, MFDBType oldType) {
        return null;
    }

    @Override
    public String translateSql(String sql) {
        return null;
    }
}
